package com.yjz.middleware.netty.one_BIO;

import lombok.extern.slf4j.Slf4j;

import java.io.*;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Desc Bio 模式服务端
 * @Author: jinzhong.yuan
 * @Date: 2018/12/25 9:47
 */
@Slf4j
public class BioServer {
  public static void main(String[] args) throws IOException {
    ServerSocket serverSocket = new ServerSocket();
    serverSocket.bind(new InetSocketAddress("127.0.0.1", 2189));
    for (; ; ) {
      Socket socket = serverSocket.accept();
      InputStream inputStream = socket.getInputStream();
      BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
      String line = reader.readLine();
      log.info("读取客户端消息: {}", line);
      OutputStream os = socket.getOutputStream();
      os.write("i am server".getBytes());
      socket.shutdownOutput();
    }
  }
}
